# with-as 语法
# with open("a.txt",'r') as fp:
#     print(fp.read())
dic = {"学号": 101, "姓名": "张三", "age": 18}
# with open("a.txt", 'w') as fp:
#     fp.write(dic) # write() 写入东西的时候必须是字符串类型
import json  # 导入json模块
# 序列化
# dumps()函数作用将python对象 转成json字符串
with open("b.txt", 'w') as fp:
    # ensure_ascii=False 关闭ascii码 处理中文乱码
    # data = json.dumps(dic,ensure_ascii=False)
    # dump()函数是dumps升级版，将write()合到参数中操作
    json.dump(dic, fp, ensure_ascii=False)
    # fp.write(data)
